home *** CD-ROM | disk | FTP | other *** search
/ Floppyshop 2 / Floppyshop - 2.zip / Floppyshop - 2.iso / art&graf.ix / art-0039 / generatr / save.c < prev   
C/C++ Source or Header  |  1997-04-16  |  19KB  |  696 lines

  1. #include <bitmap.h>
  2. #include <extdefs.h>
  3. #include <osbind.h>
  4. #include <stdio.h>
  5. #include <gemdefs.h>
  6.  
  7. /* Input a string */
  8. get_string(saying,address,max,ding)
  9. char *saying, *address;
  10. int max, ding;
  11. {
  12. char *pointer, str[3];
  13. int width, length, i, j, k, count, kp, array[10], rbox[4], x, y;
  14.  
  15.     HIDE_MOUSE;
  16.  
  17.     sscreen( SAVE );
  18.     pointer = address;
  19.     k = count = kp = 0;
  20.     display_image_names();
  21.     if( !names ) k = 30;
  22.  
  23.     /* Figure out the width according to which is longer, the
  24.         destination string or the box title */
  25.     length = strlen(saying);
  26.     if( length > max ) width = length;
  27.             else       width = max;
  28.  
  29. /* Assign the parameters to draw a box */
  30.     /* First the x coordinates */
  31.     if( !rez ) array[0] = k + 130 - width * 4 - 16, array[2] = k + 130 + width * 4 + 16;
  32.         else     array[0] = 320 - width * 4 - 16, array[2] = 320 + width * 4 + 16;
  33.  
  34.     array[6] = array[8] = array[0];
  35.     array[4] = array[2];
  36.     /* Then the y coordinates */
  37.     if( rez < 2 ) array[1] = 70, array[5] = 130;
  38.         else        array[1] = 140, array[5] = 260;
  39.     array[3] = array[9] = array[1];
  40.     array[7] = array[5];
  41.  
  42.     /* Coordinates for the filled rectangle */
  43.     rbox[0] = array[0];
  44.     rbox[1] = array[1];
  45.     rbox[2] = array[2];
  46.     rbox[3] = array[5];
  47.  
  48.     /* Set the writing mode */
  49.     vswr_mode( handle, 1 );
  50.  
  51.     /* Set fill attributes */
  52.     vsf_interior( handle, 1 );
  53.     vsf_style( handle, 8 );
  54.     vsf_color( handle, 0 );
  55.  
  56.     /* Set the line color */
  57.     vsl_color( handle, 1 );
  58.  
  59.     /* Make a box */
  60.     v_pline( handle, 5, array );
  61.     vr_recfl( handle, rbox );
  62.  
  63.     /* Now make it have a double lined border */
  64.     array[0] += 2;
  65.     array[2] -= 2;
  66.     array[1] += 2;
  67.     array[5] -= 2;
  68.     array[6] = array[8] = array[0];
  69.     array[4] = array[2];
  70.     array[3] = array[9] = array[1];
  71.     array[7] = array[5];
  72.     v_pline( handle, 5, array );
  73.  
  74.     /* Put the title on the box */
  75.     i = strlen(saying);
  76.     if( !rez ) i = k + 130 - i * 4;
  77.         else     i = 320 - i * 4;
  78.     y = array[1] + 20;
  79.     if( rez == 2 ) y += 8;
  80.     v_gtext( handle, i, y, saying );
  81.  
  82.     /* Put the underscores in place */
  83.     vst_color( handle, 1 );
  84.     if( rez == 0 )x = k + 130 - max * 4;
  85.             else  x = 320 - max * 4;
  86.     if( rez != 2 ) y = array[1] + 40;
  87.             else   y = array[1] + 80;
  88.     for( i=0; i<max; i++ ) v_gtext( handle, x + i * 8, y, "_" );
  89.  
  90.     while( kp != 13 ){
  91.  
  92.         /* Get a keypress */
  93.         kp = Crawcin();
  94.  
  95.         /* Was it a backspace? */
  96.         if( count && kp == 8 ){
  97.             v_gtext( handle, x + count * 8 - 8, y, "_" );
  98.             pointer--;
  99.             count--;
  100.             }
  101.  
  102.         /* Was it a valid digit? */
  103.         if( kp > 31 && kp < 123 ){
  104.             if( count < max ){
  105.                 str[0] = (char)kp;
  106.                 str[1] = 0;
  107.                 count++;
  108.                 v_gtext( handle, x + count * 8 - 8, y, str );
  109.                 *pointer++ = str[0];
  110.                 }else{
  111.                 if( ding ) Bconout( 2,7 );
  112.                 }
  113.             }
  114.  
  115.         /* Was it ESCAPE? */
  116.         if( kp == 27 ){
  117.             count = 0;
  118.             pointer = address;
  119.             for( i=0; i<max; i++ ) v_gtext( handle, x + i * 8, y, "_" );
  120.             }
  121.  
  122.         }/* End while( kp != 27 ) */
  123.  
  124.     /* Null terminate the string */
  125.     *pointer = 0;
  126.  
  127.     names++;
  128.     pointer = address;
  129.     j = 0;
  130.     for( i=0; i<10; i++ ){
  131.         if( *pointer == 0 ) j = 1;
  132.         if( !j ) image_names[(names-1)*10+i] = *pointer++;
  133.         else image_names[(names-1)*10+i] = 32;
  134.         }
  135.  
  136.     sscreen( RESTORE );
  137.     SHOW_MOUSE;
  138.  
  139. }/* End get_string() function */
  140.  
  141. display_image_names()
  142. {
  143. int array[10], rbox[4], i, j, k;
  144. char junk[20];
  145.  
  146.     if( names ){
  147.  
  148. /* Assign the parameters to draw a box */
  149.     /* First the x coordinates */
  150.     if( !rez ) array[0] = 217, array[2] = 319;
  151.         else   array[0] = 400, array[2] = 639;
  152.     array[6] = array[8] = array[0];
  153.     array[4] = array[2];
  154.     /* Then the y coordinates */
  155.     if( rez < 2 ) array[1] = 0, array[5] = 199;
  156.         else        array[1] = 0, array[5] = 399;
  157.     array[3] = array[9] = array[1];
  158.     array[7] = array[5];
  159.  
  160.     /* Coordinates for the filled rectangle */
  161.     rbox[0] = array[0];
  162.     rbox[1] = array[1];
  163.     rbox[2] = array[2];
  164.     rbox[3] = array[5];
  165.  
  166.     /* Set the writing mode */
  167.     vswr_mode( handle, 1 );
  168.  
  169.     /* Set fill attributes */
  170.     vsf_interior( handle, 1 );
  171.     vsf_style( handle, 8 );
  172.     vsf_color( handle, 0 );
  173.  
  174.     /* Set the line color */
  175.     vsl_color( handle, 1 );
  176.  
  177.     /* Make a box */
  178.     v_pline( handle, 5, array );
  179.     vr_recfl( handle, rbox );
  180.  
  181.     /* Now make it have a double lined border */
  182.     array[0] += 2;
  183.     array[2] -= 2;
  184.     array[1] += 2;
  185.     array[5] -= 2;
  186.     array[6] = array[8] = array[0];
  187.     array[4] = array[2];
  188.     array[3] = array[9] = array[1];
  189.     array[7] = array[5];
  190.     v_pline( handle, 5, array );
  191.  
  192.     if( rez != 2 ) v_gtext( handle, array[0]+5+rez*20, 11, "Image Names" );
  193.             else   v_gtext( handle, array[0]+25, 22, "Image Names" );
  194.  
  195.     rbox[0] += 3;;
  196.     rbox[2] -= 3;
  197.     rbox[1] += 14;
  198.     rbox[3] -= 3;
  199.  
  200.     k = 0;
  201.  
  202.     for( i=0; i<names; i++ ){
  203.  
  204.         for( j=0; j<10; j++ ) junk[j] = image_names[i*10+j];
  205.         junk[10] = 0;
  206.  
  207.         if( rez != 2 ) v_gtext( handle, array[0]+5+rez*20, array[1] + 21 + k * 8, junk );
  208.             else       v_gtext( handle, array[0]+25, array[1] + 42 + k * 16, junk );
  209.  
  210.         if( i && !( i % 19 ) && i != names - 1 ){
  211.  
  212.             if( rez != 2 ) v_gtext( handle, array[0]+5+rez*16, 191, "Press key" );
  213.                 else       v_gtext( handle, array[0]+25, 382, "Press key" );
  214.  
  215.             j = Crawcin();
  216.  
  217.             k = 0;
  218.             if( j != 27 ) vr_recfl( handle, rbox );
  219.                 else      i = 1000;
  220.  
  221.             }else{
  222.  
  223.             k++;
  224.  
  225.             }
  226.  
  227.         }
  228.  
  229.     }
  230.  
  231. }
  232.  
  233. /* Process the rectangle and then save it */
  234. image(address,format)
  235. long address;
  236. int format;
  237. {
  238. char junk[40],array[40],temp[200];
  239. int *holder, *data;
  240. int fd = -1;
  241. unsigned int append, i, j, k, numwords, counter, iterations, nplanes, width, height, wordwidth, maskflag, device, blit[8];
  242. long err, fsize, *blank;
  243. FDB source, dest;
  244. long int output();
  245.  
  246.     /* See if they want to save the mask also */
  247.     maskflag = form_alert( 1,"[2][|    Save Bit Image Mask?    |][Yes|No|Cancel]" );
  248.     do{ GET_MOUSE; } while( button );
  249.     if( maskflag == 3 ) return( 0 );
  250.     maskflag = 2 - maskflag;
  251.  
  252.     if( maskflag >= 0 ){
  253.         /* Get the output device (or cancel) */
  254.         device = form_alert( 1, "[2][|       Output Device?       |][Disk|Printer|Cancel]" );
  255.     do{ GET_MOUSE; } while( button );
  256.         }else{
  257.         device = 5;
  258.         }
  259.  
  260.     /* If printer is target device, check its readiness */
  261.     if( device == 2 ){
  262.         while( !Cprnos() && device < 3 ){
  263.             i = form_alert( 1,"[1][|Prepare Printer for Output|][Ok|Cancel]" );
  264.     do{ GET_MOUSE; } while( button );
  265.             if( i == 2 ) device = 3;
  266.             }
  267.         }
  268.  
  269.     /* If 'cancel' was not selected from output device selection...*/
  270.     if( device < 3 ){
  271.  
  272.         /* Clear the destination buffer */
  273.         blank = (long *)temp_scrn;
  274.         for( i=0; i<8000; i++ ) *blank++ = 0L;
  275.  
  276.         /* Have them enter the array name */
  277.         if( format != TO_DATA ) get_string( "Enter Array Name", array, 10, 1 );
  278.  
  279.         /* If the output device is a disk, get the filename */
  280.         if( device == 1 ){
  281.  
  282.             /* Set the extender */
  283.             switch( format ){
  284.                 case TO_C: strcpy( junk, "C" ); break;
  285.                 case TO_ASM: strcpy( junk, "S" ); break;
  286.                 case TO_GFA: strcpy( junk, "LST" ); break;
  287.                 case TO_DATA: strcpy( junk, "DAT" ); break;
  288.                 }
  289.  
  290.             /* Get file name */
  291.             HIDE_MOUSE;
  292.             sscreen( SAVE );
  293.             SHOW_MOUSE;
  294.             i = get_filename( junk );
  295.             if( !i ) names--;
  296.     do{ GET_MOUSE; } while( button );
  297.             HIDE_MOUSE;
  298.             sscreen( RESTORE );
  299.             SHOW_MOUSE;
  300.  
  301.             if( i ){
  302.  
  303.                 /* If file selected, look for it on disk */
  304.                 /* If it is there, ask if they want to append or overwrite */
  305.                 j = append = 0;
  306.                 if( Fsfirst( filename, 0 ) == 0 ){
  307.                     j = form_alert( 1, "[2][| File Already Exists! |][Replace|Append]" );
  308.     do{ GET_MOUSE; } while( button );
  309.                     if( j == 2 ){
  310.                         fd = Fopen( filename, 1 );
  311.                         Fseek( 0L, fd, 2 );
  312.                         append = 1;
  313.                         }
  314.                     }
  315.                 if( j != 2 ){
  316.                     fd = Fcreate( filename, 0 );
  317.                     for( j=0; j<10; j++ ) junk[j] = image_names[(names-1)*10+j];
  318.                     for( j=0; j<10; j++ ) image_names[j] = junk[j];
  319.                     names = 1;
  320.                     }
  321.  
  322.                 }/* End if( i ) */
  323.  
  324.             }/* End if( device == 1 ) */
  325.  
  326.         /* Either the output device is the printer or a file was
  327.             selected */
  328.         if( device == 2 || ( device == 1 && i ) ){
  329.  
  330.             /* Figure width, height, wordwidth, and number of planes */
  331.             width = abs( rx1 - rx2 ) + 1;
  332.             height = abs( ry1 - ry2 ) + 1;
  333.             switch( rez ){
  334.                 case 0: nplanes = 4; break;
  335.                 case 1: nplanes = 2; break;
  336.                 case 2: nplanes = 1; break;
  337.                 }
  338.             wordwidth = width / 16;
  339.             if( width % 16 ) wordwidth++;
  340.  
  341.             /* Set the structure address pointers */
  342.             dest.fd_addr = temp_scrn;
  343.             source.fd_addr = address;
  344.  
  345.             /* Set the source structure for the proper values */
  346.             switch( rez ){
  347.                 case 0:    source.fd_w = 320;
  348.                         source.fd_h = 200;
  349.                         source.fd_wdwidth = 20;
  350.                         source.fd_nplanes = 4;
  351.                         break;
  352.                 case 1:    source.fd_w = 640;
  353.                         source.fd_h = 200;
  354.                         source.fd_wdwidth = 40;
  355.                         source.fd_nplanes = 2;
  356.                         break;
  357.                 case 2:    source.fd_w = 640;
  358.                         source.fd_h = 400;
  359.                         source.fd_wdwidth = 40;
  360.                         source.fd_nplanes = 1;
  361.                         break;
  362.                     }
  363.  
  364.             /* Set the destination structure */
  365.             dest.fd_w = wordwidth * 16;
  366.             dest.fd_h = height;
  367.             dest.fd_nplanes = nplanes;
  368.             dest.fd_wdwidth = wordwidth;
  369.  
  370.             /* Misc structure values */
  371.             dest.fd_stand = source.fd_stand = 0;
  372.             dest.fd_r1 = source.fd_r1 = 0;
  373.             dest.fd_r2 = source.fd_r2 = 0;
  374.             dest.fd_r3 = source.fd_r3 = 0;
  375.  
  376.             i = maskflag + 1;
  377.  
  378.             while( i ){
  379.  
  380.                 i--;
  381.  
  382.                 /* How many hex words must be output */
  383.                 iterations = wordwidth * nplanes * height;
  384.  
  385.                 /* Zero the word counter ( 8 are output at a time ) */
  386.                 numwords = 0;
  387.  
  388.                 /* Array names */
  389.                 switch( format ){
  390.                     case TO_C:        strcpy( temp, "int " );
  391.                                     strcat( temp, array );
  392.                                     if( !i && maskflag ) strcat( temp, "_mask" );
  393.                                     strcat( temp, "[]={\15\12" );
  394.                                     break;
  395.                     case TO_GFA:    if( i || !maskflag )
  396.  sprintf( temp, "%s:\15\12DATA &H%04x,&H%04x,&H%04x,", array, (wordwidth*16)-1, height-1,nplanes );
  397.                                                 else     sprintf( temp, "%s_mask:\15\12DATA &H%04x,&H%04x,&H%04x,", array, (wordwidth*16)-1, height-1,nplanes );
  398.                                     numwords = 3;
  399.                                     break;
  400.                     case TO_ASM:    strcpy( temp, array );
  401.                                     if( !i && maskflag ) strcat( temp, "_mask" );
  402.                                     strcat( temp, ":\15\12" );
  403.                                     break;
  404.                                 }
  405.  
  406.                 err = 0L;
  407.                 /* Output the initial string */
  408.                 if( format == TO_ASM || format == TO_C ) err = output( temp, device, fd );
  409.  
  410.                 /* If no error... */
  411.                 if( err >= 0L ){
  412.  
  413.                     blit[0] = rx1; blit[1] = ry1;
  414.                     blit[2] = rx2; blit[3] = ry2;
  415.                     blit[4] = blit[5] = 0;
  416.                     blit[6] = width - 1;
  417.                     blit[7] = height - 1;
  418.                     vro_cpyfm( handle, 3, blit, &source, &dest );
  419.                     data = (int *)dest.fd_addr;
  420.  
  421.                     if( format != TO_DATA ){
  422.  
  423.                         for( counter=0; counter<iterations; counter++ ){
  424.  
  425.                             /* Start a new line of text */
  426.                             if( !numwords ){
  427.                                 switch( format ){
  428.                                     case TO_C: strcpy( temp, "" ); break;
  429.                                     case TO_ASM: strcpy( temp, "\11\11.dc.w " ); break;
  430.                                     case TO_GFA: strcpy( temp, "DATA " ); break;
  431.                                     }
  432.                                 }
  433.  
  434.                             /* Convert the data to ASCII format */
  435.                             if( format == TO_GFA ) strcat( temp, "&H" );
  436.                             else if( format == TO_ASM ) strcat( temp, "$" );
  437.                             else if( format == TO_C ) strcat( temp, "0x" );
  438.  
  439.                             if( !i && maskflag ){
  440.                                 if( !(counter % nplanes ) ){
  441.                                     holder = data;
  442.                                     j = 0;
  443.                                     for( k=0; k<nplanes; k++ ) j = j | *holder++;                                    
  444.                                     j ^= 0xffff;
  445.                                     *data = j;
  446.                                     }else{
  447.                                     *data = j;
  448.                                     }
  449.                                 }
  450.  
  451.                             /* Do the actual conversion */
  452.                             sprintf( junk, "%04x", *data++ );
  453.                             strcat( temp, junk );
  454.                             numwords++;
  455.  
  456.                             /* Allow only eight words across */
  457.                             if( numwords == 8 ){
  458.                                 if( format == TO_C && counter < iterations - 1 ) strcat( temp, "," );
  459.                                 strcat( temp, "\15\12" );
  460.                                 numwords = 0;
  461.                                 err = output( temp, device, fd );
  462.                                 }else if( counter < iterations - 1 ){
  463.                                 strcat( temp, "," );
  464.                                 }
  465.  
  466.                             if( err < 0L ) break;
  467.  
  468.                         }/* End counter loop */
  469.  
  470.                         if( err >= 0L ){
  471.  
  472.                             /* If any words have not been printed...*/
  473.                             if( numwords ){
  474.                                 temp[strlen(temp)]=0;
  475.                                 strcat( temp, "\15\12" );
  476.                                 output( temp,device,fd );
  477.                                 }
  478.  
  479.                             /* Close the string */
  480.                             if( format == TO_C ){
  481.                                 strcpy( junk, "};\15\12" );
  482.                                 output( junk,device,fd );
  483.                                 }
  484.  
  485.                             strcpy( junk, "\15\12" );
  486.                             output( junk,device, fd );
  487.  
  488.                             /* Make the comments (remarks) to indicate
  489.                                 the image size information */
  490.                             if( !maskflag || !i ){
  491.                                 sprintf( junk, "Width = %d\15\12", wordwidth*16 );
  492.                                 switch( format ){
  493.                                     case TO_C: strcpy( temp, "/*\15\12** " ); break;
  494.                                     case TO_ASM: strcpy( temp, "* " ); break;
  495.                                     case TO_GFA: strcpy( temp, "REM " ); break;
  496.                                     }
  497.                                 strcat( temp, junk );
  498.                                 sprintf( junk, "Height = %d\15\12", height );
  499.                                 switch( format ){
  500.                                     case TO_C: strcat( temp, "** " ); break;
  501.                                     case TO_ASM: strcat( temp, "* " ); break;
  502.                                     case TO_GFA: strcat( temp, "REM " ); break;
  503.                                     }
  504.                                 strcat( temp, junk );
  505.                                 sprintf( junk, "Word Width = %d\15\12", wordwidth );
  506.                                 switch( format ){
  507.                                     case TO_C: strcat( temp, "** " ); break;
  508.                                     case TO_ASM: strcat( temp, "* " ); break;
  509.                                     case TO_GFA: strcat( temp, "REM " ); break;
  510.                                     }
  511.                                 strcat( temp, junk );
  512.                                 sprintf( junk, "Number of planes = %d\15\12", nplanes );
  513.                                 switch( format ){
  514.                                     case TO_C: strcat( temp, "** " ); break;
  515.                                     case TO_ASM: strcat( temp, "* " ); break;
  516.                                     case TO_GFA: strcat( temp, "REM " ); break;
  517.                                     }
  518.                                 strcat( temp, junk );
  519.                                 if( format == TO_GFA ) sprintf( junk, "REM %d data words to read\15\12", wordwidth*nplanes*height+3 ), strcat( temp, junk );
  520.                                 if( format == TO_C ) strcat( temp, "*/\15\12" );
  521.                                 strcat( temp, "\15\12" );
  522.                                 err = output( temp, device, fd );
  523.                                 }
  524.  
  525.                             }/* End if( err >= 0L ) */
  526.  
  527.                         }else{
  528.  
  529.                         /* Save the block of data */
  530.                         fsize = (long int)iterations;
  531.                         fsize &= 0x0000ffff;
  532.                         fsize *= 2L;
  533.  
  534.                         if( ( i && maskflag ) || ( !i && !maskflag ) ){
  535.                             if( append ){
  536.                                 Fseek( 0L, fd, 0 );
  537.                                 Fread( fd, 2L, &append );
  538.                                 append++;
  539.                                 Fseek( 0L, fd, 0 );
  540.                                 Fwrite( fd, 2L, &append );
  541.                                 Fseek( 0L, fd, 2 );
  542.                                 }else{
  543.                                 append = 1;
  544.                                 Fwrite( fd, 2L, &append );
  545.                                 }
  546.                             }
  547.  
  548.                         if( !i && maskflag ){
  549.                             data = (int *)dest.fd_addr;
  550.                             holder = data;
  551.                             while( iterations ){
  552.                                 j = 0;
  553.                                 for( k=0; k<nplanes; k++ ) j = j | *holder++;
  554.                                 j ^= 0xffff;
  555.                                 for( k=0; k<nplanes; k++ ) *data++ = j, iterations--;
  556.                                 }
  557.                             }
  558.  
  559.                         if( ( i && maskflag ) || ( !i && !maskflag ) ){
  560.                             j = rez + maskflag * 256;
  561.                             Fwrite( fd, 2L, &j );
  562.  
  563.                             j = wordwidth * 16;
  564.                             Fwrite( fd, 2L, &j );
  565.                             Fwrite( fd, 2L, &height );
  566.                             Fwrite( fd, 4L, &fsize );
  567.                             }
  568.  
  569.                         Fwrite( fd, fsize, dest.fd_addr );
  570.                         }
  571.  
  572.                 }/* End if( err >= 0L ) */
  573.  
  574.             if( err < 0L ) form_alert( 1, "[1][|  Disk Write Error!  |][Ok]" );
  575.     do{ GET_MOUSE; } while( button );
  576.  
  577.             }/* End while( i ) */
  578.  
  579.         if( fd >= 0 ) Fclose( fd );
  580.  
  581.         }/* End if( device == 2 || ( device == 1 && i ) ) */
  582.  
  583.     }/* End if( device < 3 ) */
  584.  
  585.     graf_mkstate( &i, &i, &i, &i );
  586.  
  587. }/* End image() function */
  588.  
  589. /* Do the actual output */
  590. long output(address,device,fd)
  591. char *address;
  592. int device,fd;
  593. {
  594. unsigned int length;
  595. long err, llength;
  596.  
  597.     length = strlen(address);
  598.     llength = (long int)length;
  599.     llength &= 0x0000ffff;
  600.  
  601.     if( device == 2 ) while( *address ) Bconout( 0, *address++ );
  602.             else      err = Fwrite( fd, llength, address );
  603.  
  604.     return( err );
  605.  
  606. }/* End output() function */
  607.  
  608. /******************************************************
  609. * get_filename():                         *
  610. * This routine displays the file selector and returns *
  611. * a usable filename to the user, it also returns the  *
  612. * button which caused the file selector to exit.      *
  613. *                              *
  614. * ext: the extension of the filenames to show            *
  615. ******************************************************/
  616.  
  617. get_filename( ext )
  618. char ext[];
  619. {
  620.     char *junkp;          /* junk pointer */
  621.     char tmp_name[14];          /* filename returned by fsel_input() */
  622.     char scratch[110];          /* scratch string used to build full pathname */
  623.  
  624.     int exit_button, i, ret;  /* miscellaneous variables */
  625.  
  626.     /*
  627.     ** Initialize the strings to hold the filename returned
  628.     ** from the file selector and the filename that will be
  629.     ** returned to the calling routine.
  630.     */
  631.  
  632.     tmp_name[0] = filename[0] = '\0';
  633.  
  634.     /* append the extension to the end of pathname */
  635.     Dgetpath(scratch,Dgetdrv());
  636.     sprintf( pathname, "%c:%s", Dgetdrv()+'A', scratch );
  637.     strcpy( scratch, pathname );
  638.     strcat( scratch, "\*." );
  639.     strcat( scratch, ext );
  640.  
  641.     /* show the file selector to get the path and file names. */
  642.     ret = fsel_input( scratch, tmp_name, &exit_button );
  643.  
  644.     /* return if CANCEL was selected */
  645.     if( exit_button == 0 )  return( exit_button );
  646.  
  647.     /* return if the filename is blank */
  648.     if( tmp_name[0] == '\0' )  return(0);
  649.  
  650.     /* if the extension isn't "*" then append it to the filename */
  651.  
  652.     ret = strcmp( ext, "*" );
  653.  
  654.     if( ret != 0 )
  655.     {
  656.     /* try to find a '.' character */
  657.     i = strlen( tmp_name );
  658.     while( tmp_name[i] != '.'  &&    i >= 0 )   i--;
  659.  
  660.     /* if one was found then make the '.' an end of string char. */
  661.     if( tmp_name[i] == '.' ) tmp_name[i] = '\0';
  662.  
  663.     /* concatenate the extension to the end of the filename */
  664.     strcat( tmp_name, "." );    strcat( tmp_name, ext );
  665.     }
  666.  
  667.     /*
  668.     ** move backwards through the string and add nulls
  669.     ** until a '\' or ':' is found.  This makes a usable
  670.     ** pathname without the trailing '*','?', etc.
  671.     */
  672.  
  673.     junkp = strlen( scratch ) + scratch;
  674.  
  675.     for( ; junkp > scratch; junkp-- )
  676.      {
  677.      if( *junkp == '\\' || *junkp == ':' )    break;
  678.      *junkp = '\0';
  679.      }
  680.  
  681.     /* copy the truncated pathname back to original string */
  682.     strcpy(pathname,scratch);
  683.  
  684.     /*
  685.     ** combine the fixed path string and the filename
  686.     ** string into a full, usable pathname.
  687.     */
  688.  
  689.     strcpy( filename, scratch );
  690.     strcat( filename, tmp_name );
  691.  
  692.     /* return button selected from file selector */
  693.     return( exit_button );
  694.  
  695. }   /* End of get_filename() */
  696.